//导入 router 模块
import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";

const routes = [
    {
        path: "/",
        redirect: "/Login",
    },
    {
        path: "/Login",
        name: "Login",
        component: () => import("@/views/Login/index.vue"),
    },
    {
        path: "/SearchHotel",
        name: "SearchHotel",
        component: () => import("@/views/SearchHotel/index.vue"),
    },
    {
        path: "/OwnerList",
        name: "OwnerList",
        component: () => import("@/views/OwnerList/index.vue"),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    document.title = to.meta.title || "业主平台";
    if (to.path === "/Login") {
        next();
    } else {
        if (localStorage.getItem("token")) {
            next();
        } else {
            next("/Login");
        }
    }
});

export default router;
